import Vue from 'vue'
import Router from 'vue-router'
import Homepage from '@/pages/Homepage/Main'
import More from '@/pages/Homepage/More'
import Category from '@/pages/Goods/Category'
import Usercenter from '@/pages/Usercenter/Main'
import HomepageContainer from '@/pages/HomepageContainer'
import CommonContainer from '@/pages/CommonContainer'
import DrawMoney from '@/pages/Revenue/DrawMoney'
import RevenueDetail from '@/pages/Revenue/RevenueDetail'
import RevenueMonthly from '@/pages/Revenue/RevenueMonthly'
import RevenueRule from '@/pages/Revenue/Rule'
import Goods from '@/pages/Goods/Detail'
import GoodsComment from '@/pages/Goods/Comment'
import Phone from '@/pages/Phone/Recharge'
import AskMembership from '@/pages/Member/AskMembership'
import Members from '@/pages/Member/Members'
import OrderList from '@/pages/Order/OrderList'
import OrderDetail from '@/pages/Order/OrderDetail'
import CreateOrder from '@/pages/Order/CreateOrder'
import BuyMembership from '@/pages/Order/BuyMembership'
import PaySuccess from '@/pages/Order/PaySuccess'
import WriteComment from '@/pages/Order/WriteComment'
import Refund from '@/pages/Order/Refund'
import AddressList from '@/pages/Address/AddressList'
import AddressEdit from '@/pages/Address/AddressEdit'
import DrawCredit from '@/pages/Other/drawCredit'
import DrawCreditEntry from '@/pages/Other/drawCreditEntry'

Vue.use(Router)

const route = new Router({
    routes: [
        {
            path: '/',
            component: HomepageContainer,
            children: [{
                path: '',
                name: 'homepage',
                component: Homepage,
                meta: {title: '大唐严选'}
            }, {
                name: 'category',
                path: 'category',
                component: Category,
                meta: {title: '分类'}
            }, {
                name: 'usercenter',
                path: 'usercenter',
                component: Usercenter,
                meta: {title: '个人中心'}
            }]
        }, {
            path: '/goods',
            component: CommonContainer,
            children: [{
                path: 'detail/:preGoodsId',
                name: 'Goods',
                component: Goods,
                meta: {title: '商品详情'}
            }, {
                path: 'comment/:preGoodsId',
                name: 'goodsComment',
                component: GoodsComment,
                meta: {title: '商品评论'}
            },{
                path: 'more',
                name: 'more',
                component: More,
                meta: {title: '下期预告'}
            }]
        }, {
            path: '/user',
            name: 'User',
            component: CommonContainer,
            children: [{
                name: 'drawMoney',
                path: 'drawMoney',
                component: DrawMoney,
                meta: {title: '账户积分'}
            }, {
                name: 'revenueDetail',
                path: 'revenueDetail',
                component: RevenueDetail,
                meta: {title: '积分明细'}
            }, {
                name: 'revenueMonthly',
                path: 'revenueMonthly',
                component: RevenueMonthly,
                meta: {title: '月积分记录'}
            }, {
                name: 'rule',
                path: 'rule',
                component: RevenueRule,
                meta: {title: '会员收益'}
            }, {
                name: 'member',
                path: 'member',
                component: Members,
                meta: {title: '会员管理'}
            }, {
                name: 'askMembership',
                path: 'askMembership',
                component: AskMembership,
                meta: {title: '自助升级'}
            }]
        }, {
            path: '/order',
            component: CommonContainer,
            children: [{
                path: 'list',
                name: 'orderList',
                component: OrderList,
                meta: {title: '我的订单'}
            }, {
                path: 'detail/:orderId',
                name: 'orderDetail',
                component: OrderDetail,
                meta: {title: '订单详情'}
            }, {
                path: 'writeComment/:orderId/:goodsId',
                name: 'orderComment',
                component: WriteComment,
                meta: {title: '评价订单'}
            }, {
                path: 'refund/:orderId/:goodsId',
                name: 'orderRefund',
                component: Refund,
                meta: {title: '申请退换货'}
            }, {
                path: 'pay',
                name: 'createOrder',
                component: CreateOrder,
                meta: {title: '创建订单'}
            }, {
                name: 'buyMembership',
                path: 'buyMembership',
                component: BuyMembership,
                meta: {title: '升级创享会员'}
            }, {
                path: 'paySuccess/:id',
                name: 'paySuccess',
                component: PaySuccess,
                meta: {title: '付款成功'}
            }, {
                path: 'recharge',
                name: 'recharge',
                component: Phone,
                meta: {title: '话费充值'}
            }]
        }, {
            path: '/address',
            component: CommonContainer,
            children: [{
                path: '',
                name: 'addressList',
                component: AddressList,
                meta: {title: '地址列表'}
            }, {
                path: 'edit/:addressId',
                name: 'addressEdit',
                component: AddressEdit,
                meta: {title: '地址编辑'}
            }]
        }, {
            path: '/other',
            component: CommonContainer,
            children: [{
                path: 'drawCredit/:type',
                name: 'dawCredit',
                component: DrawCredit,
                meta: {title: '兑换积分'}
            },{
                path: 'drawCreditEntry',
                name: 'dawCreditEntry',
                component: DrawCreditEntry,
                meta: {title: '兑换积分'}
            }]
        }
    ],
    mode: 'history',//默认hash,带#
    base: '/wukong/php/WX_web/page/'
})
route.afterEach(route => {
    document.title = route.meta.title
    console.log('router change to:', route)
})

export default route
